import commonBaseURL from "./base-url";

// eslint-disable-next-line no-unused-vars
enum ResponseStatus {
  // eslint-disable-next-line no-unused-vars
  success,
  // eslint-disable-next-line no-unused-vars
  fail,
}

interface CommonResponseData {
  data: any;
  errMsg: string;
  statusCode: string;
  status: ResponseStatus;
}

// const defaultErrMsg = "网络错误，请稍后再试";
// const defaultStatusCode = "0";

type RespDataHandler = (data: any) => CommonResponseData;
const respDataHandlerMap = new Map<string, RespDataHandler>();

// baseURL.rescenterUrl返回数据标准化
respDataHandlerMap.set(commonBaseURL.rescenterUrl, (respData) => {
  if (respData.result && respData.result === "200") {
    return {
      data: respData.data,
      errMsg: "",
      statusCode: respData.result,
      status: ResponseStatus.success,
    };
  } else {
    return {
      data: null,
      errMsg: respData.errorMsg,
      statusCode: respData.result,
      status: ResponseStatus.fail,
    };
  }
});

export { respDataHandlerMap, ResponseStatus };
export type { CommonResponseData };
